<?php
/**
 * Created by PhpStorm.
 * User: 小夏
 * Date: 2016/10/10 0010
 * Time: 13:55
 */
namespace Invest\Controller;
use Common\Controller\HomebaseController;
class ListController extends HomebaseController
{
    protected $course;
    protected $activity;
    protected $user;
    protected $holdings;
    protected $assetaccount;
    function _initialize() {
        parent::_initialize();
        $this->course = M("Course");
        $this->activity = M("Activity");
        $this->user = M("Users");
        $this->holdings = M("Holdings");
        $this->assetaccount = M("AssetAccount");
    }
    //金融学吧
    function finance(){
        $where= array('delete_type'=>0);
        $classify = I('request.id');
        if($classify){
            $where['classify'] = $classify;
        }
        $count = $this->course->where($where)->count();// 查询满足要求的总记录数
        $Page  = $this->Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $list = $this->course->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        if($list){
            $teacheerids =array();
            foreach ($list as $id){
                array_push($teacheerids,$id['uid']);
            }
            $teaname= M('Users')->where(array('id'=>array('in',$teacheerids)))->getField('id,user_nicename',true);
            foreach ($list as $key=>$value){
                $list[$key]['uname'] = $teaname[$value['uid']];
            }
        }


        $this->assign('list',$list);// 赋值数据集
        $this->assign("formget",array_merge($_GET,$_POST));
        $this->assign("page", $Page->show('default'));
        $this->display(":finance");
    }
    //课程活动
    function activity(){
        $where= array('delete_type'=>0);
        $classify = I('request.id',1);
        if($classify){
            $where['act_classify'] = $classify;
        }
        $count = $this->activity->where($where)->count();// 查询满足要求的总记录数
        $Page  = $this->Page($count,9);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $list = $this->activity->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        if($list){
            $teacheerids =array();
            foreach ($list as $id){
                array_push($teacheerids,$id['uid']);
            }
            $teaname= M('Users')->where(array('id'=>array('in',$teacheerids)))->getField('id,user_nicename',true);
            foreach ($list as $key=>$value){
                $list[$key]['uname'] = $teaname[$value['uid']];
                $list[$key]['contime'] = time();
            }
        }


        $this->assign('list',$list);// 赋值数据集
        $this->assign("formget",array_merge($_GET,$_POST));
        $this->assign("page", $Page->show('default'));
        $this->display(":activity");
    }
}